package proyecto.gestionarDatosDeCursos;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

//import proyecto.BusinessLogic.NivelBLRemote;
import util.Common;

public class ObtenerDatosCursoAction extends Action {

	protected ActionForm construirDatosCursoForm(
			ActionMapping mapping,
			HttpServletRequest request)
			throws Exception {
		
		AltaCursoForm form = null;
		//NivelBLRemote nivelBLRemote = null;
		final Context context;
				
		try {	
			context = new InitialContext();					
			//cursoBLRemote = (CursoBLRemote) context.lookup("CursoBL/remote");
			//nivelBLRemote = (NivelBLRemote) context.lookup("NivelBL/remote");
		}
		catch (NamingException e)				{
			e.printStackTrace();
			throw new RuntimeException(e);				
		}
				
		form = new AltaCursoForm();
		form.reset(mapping, request);
		//form.setNiveles(nivelBLRemote.findAll());
		
		
				
		return form;
	}
	
	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,			
			HttpServletRequest request,
			HttpServletResponse response) {
								
			try {
				form = this.construirDatosCursoForm(mapping,request);
				System.out.println("despues de construir el form");				
				if ("request".equals(mapping.getScope())) {				
					request.setAttribute(mapping.getAttribute(), form);
					System.out.println("setee el form en el request");
				}				
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
											
			return mapping.findForward(Common.SUCCESS);				
	}
}
